package com.vincent.kdp.ui.fragment;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.vincent.baseapp.base.BaseFragment;
import com.vincent.baseapp.util.SPUtil;
import com.vincent.kdp.Activity.VipInfoActiviy;
import com.vincent.kdp.R;
import com.vincent.kdp.ui.bean.entity.VipInfo;
import com.vincent.kdp.ui.fragment.contract.VipContract;
import com.vincent.kdp.ui.fragment.presenter.VipPresenter;
import com.vincent.kdp.ui.vip.RegisterActivity;
import com.vincent.kdp.ui.vip.VipDetailActivity;
import com.vincent.kdp.util.BaseParam;

import butterknife.Bind;
import butterknife.OnClick;


/**
 * Created by Administrator on 2016/5/28.
 */
public class VipFragment extends BaseFragment<VipContract.View, VipPresenter> implements VipContract.View {

    @Bind(R.id.fv_vip_account_et)
    EditText mVipAccountEt;
    @Bind(R.id.login_tv)
    TextView mLoginTv;
    @Bind(R.id.register_tv)
    TextView mRegisterTv;
    @Bind(R.id.vipImg)
    ImageView vipImg;

    @Override
    protected int getLayoutResId() {
        return R.layout.fragment_vip;
    }

    @Override
    protected void initViewData() {
        Glide.with(getActivity()).load(SPUtil.getString("differentPic")).placeholder(R.mipmap
                .ic_default_image).into(vipImg);
    }

    @Override
    public VipPresenter initPresenter() {
        return new VipPresenter();
    }

    @OnClick({R.id.login_tv, R.id.register_tv})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.login_tv:
                String number = BaseParam.getDeviceId();
                if (TextUtils.isEmpty(number)) {
                    Toast.makeText(mContext,"设备号为空",Toast.LENGTH_LONG).show();
                    return;
                }
                presenter.reqVipInfo(BaseParam.getDeviceId());
                break;
            case R.id.register_tv:
                startActivity(new Intent(getActivity(), RegisterActivity.class));
                break;
        }
    }

    @Override
    public String getVipAccount() {
        return mVipAccountEt.getText().toString();
    }

    @Override
    public void setVipAccount() { mVipAccountEt.setText("");}

    @Override
    public void gotoNext(VipInfo vipInfo) {
        Intent intent = new Intent(getActivity(), VipInfoActiviy.class);
        intent.putExtra("VipInfo",vipInfo);
        startActivity(intent);
    }
}
